import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/cookieLogin")
public class cookieLogin extends HttpServlet {
    private String name = "jack";
    private String password = "000605";
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("username");
        String password = req.getParameter("password");
        if(name.equals(this.name) && password.equals(this.password)){
            Cookie cookie = new Cookie("username",name);
            resp.addCookie(cookie);
            resp.sendRedirect("welcome.jsp");
        }else{
            resp.sendRedirect("cookie_login.jsp");
        }
    }
}
